// Ninf-G-XX, ver. 0.1
// Copyright 2011 National Institute of Advanced Industrial Science and Technology
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __NC_SESSION_H__
#define __NC_SESSION_H__

#include <stdarg.h>
#include "NinfErrorCode.h"
#include "FunctionInterface.hpp"
#include "DataOutputStream.hpp"
#include "DataInputStream.hpp"
#include "ExecInfo.hpp"
#include "Submit.hpp"
#include "SessionStatus.hpp"

namespace ninf {
namespace client {

/** Session structure.
 *  This class manages one grpc_call / Ninf_call
 */
class Session {
  static int         counter;
public:
  bool                syncFlag;
  FunctionInterface * interface;
  Arg               * args;
  int                 id;
  SessionStatus       status;
  NinfErrorCode       errorCode;

  Submit            * submit;

  /** this vector stores strings to be free */
  vector <const char *>       toFree;

  Session(const char * entry, bool syncFlag);
  ~Session();

  void setupMeta();
  void writeOutMeta(
      const string & inputFilePrefix,
      const string & outputFilePrefix,
      const string & metaFilePrefix);

  void writeOut(const string & outputFilePrefix);
  void readIn  (const string & inputFilePrefix);

  NinfErrorCode invoke(va_list ap);
  NinfErrorCode recvData();
  NinfErrorCode abort();
};
}
}
#endif
